#!/bin/bash

config=~/.wsconfig
baseJobName=`grep "baseJobName" $config | cut -d " " -f 3`
outFile=`ls out.${1}*`
resDir=res.${1}
echo "First 80 lines:" > ${1}
head -80 ${outFile} >> ${1}
echo "Last 80 lines:" >> ${1}
tail -n 80 ${outFile} >> ${1}
mv ${1} $resDir
 
rsFile=`ls -t ${resDir}/restart/ | head -n 1 | cut -d . -f 1`
mv ${resDir}/restart/${rsFile}* ${resDir}
rm -rf ${resDir}/restart

cp input $resDir -r > /dev/null 2>&1
cp DDInitial.plt $resDir > /dev/null 2>&1

job=`ls ${baseJobName}* | head -n 1`
cp gen $resDir > /dev/null 2>&1
cp $job $resDir > /dev/null 2>&1

rm ${resDir}/core* -f > /dev/null 2>&1
